//
//  MineRequestModel.swift
//  TianTianBiTing
//
//  Created by Gox mac 2 on 2019/1/3.
//  Copyright © 2019 Gox_WallyDiao. All rights reserved.
//

import UIKit
import Alamofire
import SwiftyJSON
import HandyJSON

class MineRequestModel {
    class func loadExchangeRate(completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [ExchangeRateModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_ExchangeRate, jointArr: nil, parameters: nil) { (json) in
            if json["code"].stringValue == SUCCESS {
                var bannerModels = [ExchangeRateModel]()
                let arr = json["data"].arrayValue
                for dic in arr {
                    let model = JSONDeserializer<ExchangeRateModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["message"].stringValue, bannerModels)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }
    
    class func loadWalletBalance(jointArr:[Any], completion:@escaping (_ succeed: Bool,_ message: String,_ left:NSNumber, _ right:NSNumber) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_WalletBalance, jointArr: jointArr, parameters: nil) { (json) in
            if json["code"].stringValue == SUCCESS {
                let dic = json["data"].dictionaryObject
                let model = JSONDeserializer<WalletBalanceModel>.deserializeFrom(dict: dic)
            
                completion(true, json["message"].stringValue, model?.balance ?? 0.0, model?.commission ?? 0.0)
            } else {
                completion(false, json["message"].stringValue, 0.0,0.0)
            }
        }
    }
    
    class func feekBack(parameters:[String : Any], completion:@escaping (_ succeed: Bool, _ message:String) -> ()) {
        TTNetworkTools.postRequestData(URLString: TTURL_Feekback, jointArr: nil, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS {
                completion(true, "反馈成功")
            } else {
                completion(false, json["message"].stringValue)
            }
        }
    }
    
    class func loadPkgRecord(parameters:[String : Any], programId:[Any], completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [PkgRecordModel]?, _ totalpage:Int?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_PkgRecord, jointArr: programId, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS {
                var bannerModels = [PkgRecordModel]()
                let dic = json["data"].dictionaryValue
                let arr = dic["data"]!.arrayValue
                for dic in arr {
                    let model = JSONDeserializer<PkgRecordModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["message"].stringValue, bannerModels,dic["totalPages"]?.intValue)
            } else {
                completion(false, json["message"].stringValue, nil,0)
            }
        }
    }
    
    class func loadUserInfo(parameters:[String : Any], completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList:UserInfoModel?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_UserDetailInfo, jointArr: nil, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS {
                let dic = json["data"].dictionaryObject
                let model = JSONDeserializer<UserInfoModel>.deserializeFrom(dict: dic)
                
                completion(true, "", model)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }
    
    class func WX_Logion(str:String, completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList:UserInfoModel?) -> ()) {
        TTNetworkTools.postRequestData(URLString: TTURL_WXLogin, jointArr: [str], parameters: ["platSource": "ios"]) { (json) in
            if json["code"].stringValue == SUCCESS {
                let dic = json["data"].dictionaryObject
                let model = JSONDeserializer<UserInfoModel>.deserializeFrom(dict: dic)
                
                completion(true, "", model)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }
    
    class func LoadVerCode(jointArr: [Any],parameters:[String : Any], completion:@escaping (_ succeed: Bool,_ message: String) -> ()) {
        TTNetworkTools.postRequestData(URLString: TTURL_VerCode, jointArr: jointArr, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS {
                
                completion(true, "获取验证码成功")
            } else {
                completion(false, json["message"].stringValue)
            }
        }
    }
    
    class func CheckVerCode(parameters:[String : Any], completion:@escaping (_ succeed: Bool,_ message: String) -> ()) {
        TTNetworkTools.postRequestData(URLString: TTURL_CheckVerCode, jointArr: nil, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS {
                
                completion(true, "")
            } else {
                completion(false, json["message"].stringValue)
            }
        }
    }
    
    class func CheckPay(parameters:[String : Any], completion:@escaping (_ succeed: Bool,_ message: String) -> ()) {
//        TTNetworkTools.postRequestData(URLString: TTURL_CheckPay, jointArr: nil, parameters: parameters) { (json) in
//            if json["code"].stringValue == SUCCESS {
//
//                completion(true, "")
//            } else {
//                completion(false, json["message"].stringValue)
//            }
//        }
        TTService.shared.requestNew(TTURL_CheckPay, method: .post, parameters: parameters, headers: nil) { (json) in
            if json["code"].stringValue == SUCCESS {
                
                completion(true, "")
            } else {
                completion(false, json["message"].stringValue)
            }
        }
    }
    
    class func requestWithdrawal(jointArr: [Any], completion:@escaping (_ succeed: Bool,_ message: String) -> ()) {
        TTNetworkTools.postRequestData(URLString: TTURL_Withdraw, jointArr: jointArr, parameters: nil) { (json) in
            if json["code"].stringValue == SUCCESS {
                completion(true, "提现申请成功")
            } else {
                completion(false, json["code"].stringValue)
            }
        }
    }
    
    class func loadNews(parameters:[String : Any], completion:@escaping (_ succeed: Bool,_ message: String,_ bannerList: [NewsModel]?) -> ()) {
        TTNetworkTools.getRequestData(URLString: TTURL_PushMsgList, jointArr: nil, parameters: parameters) { (json) in
            if json["code"].stringValue == SUCCESS && json["data"].dictionaryValue != nil {
                var bannerModels = [NewsModel]()
                let dic = json["data"].dictionaryValue
                guard (dic["data"]?.arrayValue) != nil else {
                    completion(false, "没有数据", nil)
                    return
                }
                let arr = dic["data"]!.arrayValue
                for dic in arr {
                    let model = JSONDeserializer<NewsModel>.deserializeFrom(dict: dic.dictionaryObject)
                    bannerModels.append(model!)
                }
                completion(true, json["message"].stringValue, bannerModels)
            } else {
                completion(false, json["message"].stringValue, nil)
            }
        }
    }
}
